﻿using spacex.util.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace spacex.camInterface
{
    /// <summary>
    /// Represents a PanCam interface class
    /// </summary>
    public class PanCam : IPanCam
    {
        protected List<ICamObserver> panCamObservers;
        private bool connectionEstablished;
        private bool imageCaptured;
        private StormBrick stormBrick;

        public bool ConnectionEstablished
        {
            get { return connectionEstablished; }
            set { connectionEstablished = value; }
        }

        public bool ImageCaptured
        {
            get { return imageCaptured; }
            set { imageCaptured = value; }
        }

        /// <summary>
        /// Public constructor
        /// </summary>
        public PanCam()
        {
            panCamObservers = new List<ICamObserver>();
            ConnectionEstablished = false;
            ImageCaptured = false;

            stormBrick = new StormBrick();
        }

        /// <summary>
        /// Captures an image from the pancam camera
        /// </summary>
        public void TakeImage(int exposureTime)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Called when the camera has finished capturing an image, all observers are informed
        /// </summary>
        public void CaptureComplete()
        {
            foreach(ICamObserver observer in panCamObservers){
                observer.Update();
            }
        }

        /// <summary>
        /// Allows obeservers to register for updates from the camera
        /// </summary>
        /// <param name="observer"></param>
        public void RegisterToCameraUpdates(ICamObserver observer)
        {
            panCamObservers.Add(observer);
        }

        /// <summary>
        /// Method attempts to connect to the pan cam
        /// </summary>
        /// <returns></returns>
        public bool ConnectToPanCam()
        {
            return stormBrick.Connect();
        }
    }
}
